<?php
error_reporting(E_ALL);
$url='http://ww.vendertec.com/ext';
function send_post($url, $post_data) {
	$postdata = http_build_query($post_data);
	$options = array(
			'http' => array(
					'method' => 'POST',
					'header' => 'Content-type:application/x-www-form-urlencoded',
					'content' => $postdata,
					'timeout' => 15 * 60 // 超时时间（单位:s）
			)
	);
	$context = stream_context_create($options);
	$result = file_get_contents($url, false, $context);
	return $result;
}

//$data=send_post($url, $post_data);
//var_dump($data);


function http_post_json($url, $jsonStr)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Content-Type: application/json; charset=utf-8',
			'Content-Length: ' . strlen($jsonStr)
	)
			);
	$response = curl_exec($ch);
	var_dump($jsonStr);
	var_dump($response);
	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	
	
	var_dump($httpCode);
	curl_close($ch);

	return array($httpCode, $response);
}


$rand=rand(1,999);
$str='r='.$rand.'&type=1004&vid=2&key=e597c50faf25d111f418e8c9a72a0e21';
$sign=md5($str);
$post_data = array(
		'type' => 1004,
		'vid' => 2,
		'r' => $rand,
		'sign' =>$sign
);

$jsonStr = json_encode($post_data);
list($returnCode, $returnContent) = http_post_json($url, $jsonStr);
var_dump($returnContent);
var_dump($returnCode);

